

from flask import Blueprint

from app import proc
from app import test
# from app.chess import pika_pool

main_app = Blueprint('main', __name__)


@main_app.route("/api/<version>/test", methods=["POST"])
def api_test(version):
    from app.machine import test_module
    from app.tools import proc_request_data

    params = proc_request_data()
    # res = machine_move(3, 'R')
    # print("machine_move:", res)
    # data = test_module(params)
    data = None

    test.proc_test_api(params)

    return {
        "error": 0,
        "data": data
    }


# 创建一局游戏
@main_app.route("/api/<version>/create_game", methods=["POST"])
@proc.require_login
def create_game(version):
    return proc.api_create_game()


# 创建一局AI游戏
@main_app.route("/api/<version>/start_ai_chess", methods=["POST"])
@proc.require_login
def start_ai_chess(version):
    return proc.api_start_ai_chess()


# 进行一局游戏
@main_app.route("/api/<version>/chess_game_process", methods=["POST"])
@proc.require_login
def chess_game_process(version):
    return proc.api_chess_game_process()


#
@main_app.route("/api/<version>/wait_opponent_move", methods=["POST"])
@proc.require_login
def wait_opponent_move(version):
    return proc.api_wait_opponent_move()


@main_app.route("/api/<version>/wait_pika_move", methods=["POST"])
@proc.require_login
def wait_pika_move(version):
    return proc.api_wait_pika_move()


@main_app.route("/api/<version>/get_pika_move", methods=["POST"])
@proc.require_login
def get_pika_move(version):
    return proc.api_get_pika_move()


# 装载一局游戏
@main_app.route("/api/<version>/load_chess_game", methods=["POST"])
@proc.require_login
def load_chess_game(version):
    return proc.api_load_chess_game()


# 获取一局游戏的历史数据
@main_app.route("/api/<version>/get_match_history", methods=["POST"])
@proc.require_login
def get_match_history(version):
    return proc.get_match_history()


# 获取机器计算的象棋走法
@main_app.route("/api/<version>/cal_machine_move", methods=["POST"])
@proc.require_login
def cal_machine_move(version):
    return proc.cal_machine_move()


# 复位一局游戏
@main_app.route("/api/<version>/reset_chess_game", methods=["POST"])
def reset_chess_game(version):
    return proc.api_reset_chess_game()


# 一局游戏倒退几步
@main_app.route("/api/<version>/rewind_chess_game", methods=["POST"])
def rewind_chess_game(version):
    return proc.api_rewind_chess_game()


# 用户注册
@main_app.route("/api/<version>/user/register", methods=["POST"])
def user_register(version):
    return proc.api_user_register()


# 用户登录
@main_app.route("/api/<version>/user/login", methods=["POST"])
def user_login(version):
    return proc.api_user_login()


# 用户登出
@main_app.route("/api/<version>/user/logout", methods=["POST"])
def user_logout(version):
    return proc.api_user_logout()


# 测试接口
@main_app.route("/api/<version>/test", methods=["POST"])
@proc.require_login
def port_test(version):
    return proc.api_test()


# 进入游戏专场
@main_app.route("/api/<version>/game/enter_district", methods=["POST"])
@proc.require_login
def game_enter_district(version):
    return proc.api_game_enter_district()


# 退出游戏专场
@main_app.route("/api/<version>/game/exit", methods=["POST"])
@proc.require_login
def game_exit_district(version):
    return proc.api_game_exit_district()

